package com.hspedu.spring.hspapplicationcontext;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Charlie
 * @version 1.0
 * @date 28/10/2025 下午8:24
 */
public class HspApplicationContext {
    private ConcurrentHashMap<String, Object> singletonObjects =
            new ConcurrentHashMap<>();

    public HspApplicationContext(String iocBeanXmlFile) throws DocumentException {
        String path = this.getClass().getResource("/").getPath();
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(new File(path + iocBeanXmlFile));

        Element rootElement = document.getRootElement();
        Element bean = (Element) rootElement.elements("bean").get(0);
        String id = bean.attributeValue("id");
        String aclass = bean.attributeValue("class");
        List<Element> property = bean.elements("property");
        Integer monsterId =
                Integer.parseInt(property.get(0).attributeValue("value"));


        System.out.println("id=" + id + "monserId=" + monsterId);


    }

}
